<?php
namespace Mp\Service\Widget;
use Illuminate\Contracts\Support\Renderable;
use Mp\Service\Common\Asset;

class Tag extends Input{

	//protected $symbol ;

	protected $name = 'tag';

	protected $max = 5;	//添加标签最多数量

	protected $value = [];

	protected $view = 'Mp::widgets.tag';


	protected $css = [
		'static/mp/assets/plugins/bootstrap-tagsinput/dist/bootstrap-tagsinput.css',
	];

	protected $js = [
		'static/mp/assets/plugins/bootstrap-tagsinput/dist/bootstrap-tagsinput.js',
	];

	protected $script ; 

	protected function _init($params){
		Asset::css($this->css);
		Asset::js($this->js);
		
		$this->symbol = 'tag-'.str_random();
		$this->script = <<<SCRIPT
$('.tags_add_max').tagsinput({
        maxTags: {$this->max}
    });

SCRIPT;
	Asset::script($this->script);

		$this->data = [
			'name' => $this->name,
			'value' => $this->value,
			'symbol' => $this->symbol,
		];

	}

	public function default(array $tags){

		$this->value = array_merge($this->value,(array)$tags);
		$this->data['value'] = $this->value;
		return $this;
	}


}